import { unEnumList,enumList,basicSlotQaList,basicSlotDialogList,basicDictSlotList,BasicDictSysList,dictionaryList,loadDictItemsForJson,dictionaryAdd,dictionaryDelete,dictionaryUpdateDictName,dictionaryEditDictItems,dictionaryDelDictItems,editAllDictItems,exporta,templateA } from '@/services/basiccapacity';

export default {
  namespace: 'customDictionary',

  state: {
    total:'',
    list:[],
    _id:'',
    word:'',
    synWords:[],
    isUsed:null,
  },
  effects: {
    *enumList({ payload, callback }, { call, put }) { // 可枚举类型可枚举类型列表
      const response = yield call(enumList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *unEnumList({ payload, callback }, { call, put }) { // 不可枚举类型列表
      const response = yield call(unEnumList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetch({ payload, callback }, { call, put }) {
      const response = yield call(dictionaryList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetchb({payload,callback},{call,put}){
      const responses = yield call(loadDictItemsForJson,payload);
      if (responses) {
        if (callback && typeof callback === 'function') {
          callback(responses);
        }
        yield put({
          type: 'saves',
          payload: responses,
        });
      }
    },
    *fetchc({ payload, callback }, { call, put }) {
      const response = yield call(dictionaryAdd, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetchd({ payload, callback }, { call, put }) {
      const response = yield call(dictionaryDelete, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetche({ payload, callback }, { call, put }) {
      const response = yield call(dictionaryUpdateDictName, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetchf({ payload, callback }, { call, put }) {
      const response = yield call(dictionaryEditDictItems, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetchg({ payload, callback }, { call, put }) {
      const response = yield call(dictionaryDelDictItems, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetchh({ payload, callback }, { call, put }) {
      const response = yield call(editAllDictItems, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *exporta({ payload, callback }, { call, put }) {
      const response = yield call(exporta, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *templateA({ payload, callback }, { call, put }) {
      const response = yield call(templateA, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *BasicDictSysList({ payload, callback }, { call, put }) {
      const response = yield call(BasicDictSysList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *basicDictSlotList({ payload, callback }, { call, put }) { // 实体管理 使用中词槽列表
      const response = yield call(basicDictSlotList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *basicSlotDialogList({ payload, callback }, { call, put }) { // 词槽管理 词槽使用中的多轮列表
      const response = yield call(basicSlotDialogList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *basicSlotQaList({ payload, callback }, { call, put }) { // 词槽管理 词槽使用中的知识点列表
      const response = yield call(basicSlotQaList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    fetchb(state,{payload}){
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        total:'',
        list:[]
      };
    },
  },
};
